execute as @e[type=item_frame,nbt={Tags:["item_keeper"]}] run data modify entity @s ItemRotation set value 0
execute as @e[type=item_frame,nbt={Tags:["item_keeper"]}] at @s if entity @e[distance=..1.5,type=item_frame,nbt={Tags:["wire"]},tag=hasPower] if entity @e[distance=..1,type=item,tag=!keep_from_delete] run tag @e[distance=..1.5,type=item_frame,nbt={Tags:["wire"]},tag=hasPower,limit=1,sort=random] remove hasPower
execute as @e[type=item_frame,nbt={Tags:["item_keeper"]}] at @s if entity @e[distance=..1.5,type=item_frame,nbt={Tags:["wire"]},tag=hasPower] if entity @e[distance=..1,type=item,tag=!keep_from_delete] run execute as @e[type=item_frame,nbt={Tags:["item_keeper"]}] at @s run execute as @e[type=item,distance=..1] run data modify entity @s Health set value 32767
execute as @e[type=item_frame,nbt={Tags:["item_keeper"]}] at @s if entity @e[distance=..1.5,type=item_frame,nbt={Tags:["wire"]},tag=hasPower] if entity @e[distance=..1,type=item,tag=!keep_from_delete] run execute as @e[type=item_frame,nbt={Tags:["item_keeper"]}] at @s run execute as @e[type=item,distance=..1] run data modify entity @s Age set value -32768
execute as @e[type=item_frame,nbt={Tags:["item_keeper"]}] at @s if entity @e[distance=..1.5,type=item_frame,nbt={Tags:["wire"]},tag=hasPower] if entity @e[distance=..1,type=item,tag=!keep_from_delete] run execute as @e[type=item_frame,nbt={Tags:["item_keeper"]}] at @s run tag @e[type=item,distance=..1] add keep_from_delete

execute as @e[type=item_frame,nbt={Tags:["item_keeper"]}] at @s unless block ~ ~-1 ~ blue_glazed_terracotta run kill @s